﻿using System;

namespace DisplaySC
{
    internal class TypeConvert
    {
        public static int ToInt32(string value, int def)
        {
            if (String.IsNullOrEmpty(value))
                return def;

            try
            {
                return Convert.ToInt32(value);
            }
            catch (FormatException)
            {
                return def;
            }
        }

        public static bool ToBoolean(string value)
        {
            if (String.IsNullOrEmpty(value))
                return false;

            try
            {
                return Convert.ToBoolean(value);
            }
            catch (FormatException)
            {
                return false;
            }
        }

        public static bool ToBoolean(string value, bool def)
        {
            if (String.IsNullOrEmpty(value))
                return def;

            try
            {
                return Convert.ToBoolean(value);
            }
            catch (FormatException)
            {
                return def;
            }
        }
    }
}
